const express = require("express");
const nedb = require("nedb");
const rest = require("express-nedb-rest");
const cors = require("cors");

const app = express();
const coffeesDataStore = new nedb({
  filename: "coffeeLog.db",
  autoload: true,
});

const typeDataStore = new nedb({
  filename: "coffeeType.db",
  autoload: true,
});

const restAPI = rest();
restAPI.addDatastore("coffees", coffeesDataStore);
restAPI.addDatastore("types", typeDataStore);

app.use(cors());
app.use("/", restAPI);

app.listen(4000, () => {
  console.log("API ready at http://localhost:4000");
});
